<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width='device-width', initial-scale=1.0">
  <style>
    #result{
      width: 300px;
      height: 100px;
      border: 1px solid olivedrab;
    }
  </style>
</head>
<body>
  <button>发送请求</button>
  <div id="result">
  </div>
</body>
<script>
  const btn = document.querySelector('button')
  btn.onclick=function(){
    //1.创建对象
    const x = new XMLHttpRequest()
    //2.初始化设置
    x.open('GET','http://127.0.0.1:8000/cors-server')
    //3.发送
    x.send()
    //4.绑定事件
    x.onreadystatechange = function(){
      if(x.readyState===4){
        if(x.status>=200&&x.status<300){
          console.log(x.response);
        }
      }
    }


  }


</script>

</html>